<?php
interface condition_status_info
{	
	//Condition functions
	function insert_condition($conName,$discription);	
	function update_condition($conID,$conName,$discription);
	function delete_condition($conID);
	function get_condition_list();
	//Chứng thực ID của condition và status
	function validateID($ID);
	function checkExistCon($ID);
	
	//Status functions
	function insert_status($statusName,$discription);
	function update_status($statusID,$statusName,$discription);
	function delete_status($statusID);
	function get_status_list();	
}

class condition_status implements condition_status_info
{
	function condition_status()
	{
		@session_start(); 
		require_once('../../lib/'.'BaseDir.inc.htm');
		require_once(EIU_LIB.'DBCommon.class.htm');	
	}
	
	//check Exist Condition
	function checkExistCon($ID)
	{
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();
		
		$q_select_conid = "SELECT COUNT(CONID) as count FROM `condition_tbl` WHERE `CONID`='".$ID."' AND isDeleted = 0";
		echo $q_select_catid;
		$rs_select = $oDB->stl_db_select($q_select_conid, $conn);
		
		$oDB->stl_closeConn($conn);
		
		if($rs_select[0]->count<=0){
			return false;
		}else{
			return true;
		}
	}
	
	//check Exist Status
	function checkExistSta($ID)
	{
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();
		
		$q_select_conid = "SELECT COUNT(STAID) as count FROM `status_tbl` WHERE `STAID`='".$ID."' AND isDeleted = 0";
		echo $q_select_catid;
		$rs_select = $oDB->stl_db_select($q_select_conid, $conn);
		
		$oDB->stl_closeConn($conn);
		
		if($rs_select[0]->count<=0){
			return false;
		}else{
			return true;
		}
	}
	
	//Get list functions
	function get_condition_list()
	{
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();
		
		$q = "
			SELECT CONID,CONName,DescriptionCon FROM condition_tbl 
			WHERE `isDeleted`=0 ORDER BY `CONName` ASC
		";
		//echo $q;
		
		$rs = $oDB->stl_db_select($q, $conn);
		
		$oDB->stl_closeConn($conn);
		
		if($rs)	return $rs;
		else return false;	
	}
	
	function get_status_list()
	{
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();
		
		$q = "
			SELECT STAID,STAName,DescriptionSta FROM `status_tbl`
			WHERE `isDeleted`=0 ORDER BY `STAName` ASC
		";
		$rs = $oDB->stl_db_select($q, $conn);
		
		$oDB->stl_closeConn($conn);
		
		if($rs)	return $rs;
		else return false;	
	}
	
	//Insert functions
	function insert_condition($conName,$discription){
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();

		$q_insert = "
			INSERT INTO `condition_tbl` (`CONName`, `DescriptionCon`, `ModifiedBy`, `isDeleted`, `CreateDate`, `LastUpdate`) 
			VALUES ('".$conName."', '".$discription."', '".SB_MH5."',0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
		";		
		echo $q_insert;
		$rs_insert = $oDB->stl_db_select($q_insert, $conn);
		//close connection
		$oDB->stl_closeConn($conn);
		
		//return value
		if($rs_insert) return true;
		else return false;
	}
	
	function insert_status($statusName,$discription){
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();

		$q_insert = "
			INSERT INTO `status_tbl` (`STAName`, `DescriptionSta`, `ModifiedBy`, `isDeleted`, `CreateDate`, `LastUpdate`) 
			VALUES ('".$statusName."', '".$discription."', '".SB_MH5."',0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
		";		
		
		$rs_insert = $oDB->stl_db_select($q_insert, $conn);
		//close connection
		$oDB->stl_closeConn($conn);
		
		//return value
		if($rs_insert) return true;
		else return false;
	}
	
	//Update functions
	function update_condition($conID,$conName,$discription){
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();
	
		$q_update = "UPDATE `condition_tbl` SET `CONName` = '".$conName."',	`DescriptionCon`= '".$discription."',						
							`LastUpdate`= CURRENT_TIMESTAMP,`ModifiedBy`= '".SB_MH5."' WHERE `condition_tbl`.`CONID` =".$conID;
		
		$rs_update = $oDB->stl_db_change($q_update, $conn);
		//echo $q_update."<br/>";
		$oDB->stl_closeConn($conn);
		
		//return value
		if($rs_update) return true;
		else return false;
	}
	
	function update_status($staID,$staName,$discription){
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();
	
		$q_update = "UPDATE `status_tbl` SET `STAName` = '".$staName."',	`DescriptionSta`	= '".$discription."',						
							`LastUpdate`= CURRENT_TIMESTAMP,`ModifiedBy`= '".SB_MH5."' WHERE `status_tbl`.`STAID` =".$staID;
		
		echo $q_update;
		$rs_update = $oDB->stl_db_change($q_update, $conn);
		
		$oDB->stl_closeConn($conn);
		
		//return value
		if($rs_update) return true;
		else return false;
	}
	
	//Delete functions
	function delete_condition($conID){
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();
		
		$q_update = "UPDATE `condition_tbl` SET `isDeleted` = '1',`LastUpdate`= CURRENT_TIMESTAMP,`ModifiedBy`= '".SB_MH5."' WHERE `condition_tbl`.`CONID` =".$conID;
		//echo $q_update;
		$rs_update = $oDB->stl_db_change($q_update, $conn);
		
		$oDB->stl_closeConn($conn);		
		
		//return value
		if($rs_update) return true;
		else return false;
		
	}
	
	function delete_status($staID){
		$oDB = new DBCommon();
		$conn =  $oDB->stl_openConn();
		
		$q_update = "UPDATE `status_tbl` SET `isDeleted` = '1',`LastUpdate`= CURRENT_TIMESTAMP,`ModifiedBy`= '".SB_MH5."' WHERE `status_tbl`.`STAID` =".$staID;
		
		$rs_updaters_update = $oDB->stl_db_change($q_update, $conn);
		
		$oDB->stl_closeConn($conn);		
		
		//return value
		if($rs_update) return true;
		else return false;		
	}
	
	function validateID($ID){
		//ID là số nguyên
		if(is_numeric($ID)) return true;
		return false;
	}
	
	
}
?>